<?php
namespace app\admin\controller;
use app\admin\validate\Admin as AdminValidate;
use think\Controller;

class Index extends Base
{
	/**
	 * 后台首页 
	 */
    public function index()
    {
    	if(session("?msg")){
  			$msg=session('msg');
  		}else{
  			$msg='';
  		}
  		$this->assign('msg',$msg);
      return $this->fetch();
    }
    /**
     * 后台欢迎页面
     */
    public function welcome()
    {
    	return $this->fetch();
    }
     /**
     * 后台登陆页面
     */
    public function login()
    {
    	if($this->request->isPost()){
        $validate = new AdminValidate;
    		$result = $validate
          ->scene('login')
          ->check(input());
    		if($result!==true){
          $result = $validate->getError();
  				return $this->error($result);
  			}
			$result=model('Admin')->doLogin();
			if($result !== true){
				return $this->error($result);
			}
    		return $this->success('登陆成功');
    	}else{
    		if(session("?msg")){
    			$msg=session('msg');
    		}else{
    			$msg='';
    		}
    		$this->assign('msg',$msg);
    		return $this->fetch();
    	}	
    }

    /**
     * 后台退出登陆
     */
    public function outlogin(){
    	session('uid',null);
    	session('uname',null);
      return $this->redirect('admin/index/index');
    }

}
